package com.dnjn.happiness.survey.controller.admin;

import com.dnjn.happiness.common.cloud.controller.BaseController;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.common.security.annotation.RequiresPermissions;
import com.dnjn.happiness.survey.domain.Question;
import com.dnjn.happiness.survey.service.IQuestionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 题目Controller
 *
 * @author happiness
 * @date 2023-10-24
 */
@Tag(name = "admin survey question 题目", description = "题目")
@RestController
@RequestMapping("/admin/question")
public class AdminQuestionController extends BaseController {
    @Autowired
    private IQuestionService questionService;




    @PostMapping("/querySurveyBySurveyId")
    @Operation(summary = "我的-我的问卷-查看问卷")
    public AjaxResult querySurveyBySurveyId(@RequestBody Question domain) {
        List<Question> list = questionService.querySurveyBySurveyId(domain);
        return success(list);
    }

    @RequiresPermissions("survey:question:query")
    @PostMapping("/querySurveyQuestionBySurveyId")
    @Operation(summary = "后台-我的-我的问卷-查看问卷")
    public AjaxResult querySurveyQuestionBySurveyId(@RequestParam Long surveyId, Long userId) {
        Assert.notNull(userId, "userId不能为空!");
        Assert.notNull(surveyId, "surveyId不能为空!");
        List<Question> questionList = questionService.lambdaQuery().eq(Question::getSurveyId, surveyId).eq(Question::getDeleted, "0").list();
        List<Question> list = questionService.querySurveyQuestionBySurveyId(surveyId, userId);
        if (list.size() > 0) {
            return success(list);
        } else {
            return success(questionList);
        }
    }

    @RequiresPermissions("survey:question:query")
    @PostMapping("/querySurveyQuestionAnalysis")
    @Operation(summary = "后台-我的问卷-查看问卷答题详情-题目分析")
    public AjaxResult querySurveyQuestionAnalysis(@RequestParam Long surveyId) {
        Assert.notNull(surveyId, "surveyId不能为空!");
        List<Question> questionList = questionService.querySurveyQuestionAnalysis(surveyId);

        return AjaxResult.success(questionList);
    }
}
